package com.taku.controller;

import com.taku.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/**
 * @Author: taku
 * @CreateTime: 2020-05-13 11:06
 * @Description:
 */
@RequestMapping("/user")
@Controller
public class MyController {

    @RequestMapping("/get")
    public String test(Model model) {
        model.addAttribute("hello","你好,这里是服务器");
        User user = new User(1, "李四", "北京");
        model.addAttribute("user", user);

        List<User> users = new ArrayList<User>();
        users.add(new User(1,"张三","深圳"));
        users.add(new User(2,"李四","北京"));
        users.add(new User(3,"王五","武汉"));
        model.addAttribute("users",users);


        //Map定义
        Map<String,Object> dataMap = new HashMap<String,Object>();
        dataMap.put("No","123");
        dataMap.put("address","深圳");
        model.addAttribute("dataMap",dataMap);

        // 数组测试
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);

        //日期
        model.addAttribute("now",new Date());

        //if条件
        model.addAttribute("age",22);

        // javascript 内联
        model.addAttribute("mess1","你好时间");
        model.addAttribute("mess2","helloworld");
        return "index";
    }

    @RequestMapping("/test")
    public String action(Model model) {
        model.addAttribute("hello","hello  action");
        System.out.println("hello");
        return "index";
    }

}
